<template>
  <div class="index-box" ref="index">
      <div class="menuList" ref="menuList">
        <div class="menu-item" :class="[item.orderStatus==searchForm.orderStatus?'active':'']"  @click="handleItem(item.orderStatus)" v-for="(item,index) in menuList">
          <div class="numberBox">
            <span class="number">{{item.orderCount}}</span>
          </div>
          <div class="text">{{item.statusName}}</div>
        </div>
      </div>
        <div class="search" ref="search">
         <el-form :inline="true" :model="searchForm" size="small" ref="searchForm" @submit.native.prevent
           class="demo-form-inline" id="searchBox">
           <el-form-item prop="orderCode">
               <el-input v-model="searchForm.orderCode" clearable placeholder="订单编号" style="width:230px !important;"></el-input>
           </el-form-item>
           <el-form-item prop="goodsName">
               <el-input v-model="searchForm.goodsName" clearable placeholder="商品名称"></el-input>
           </el-form-item>
           <el-form-item prop="telephone">
               <el-input v-model="searchForm.telephone" clearable placeholder="用户手机号"></el-input>
           </el-form-item>

           <el-form-item prop="orderTime">
             <el-date-picker v-model="orderTime" type="daterange" align="right" unlink-panels range-separator="至"
               start-placeholder="创建开始日期" end-placeholder="创建结束日期" format="yyyy-MM-dd" value-format="yyyy-MM-dd"
               :picker-options="pickerOptions">
             </el-date-picker>
           </el-form-item>
           <el-form-item class="clearfix">
             <el-button type="primary" @click="handleSearch()" icon="el-icon-search">查询</el-button>
             <el-button icon="el-icon-refresh" size="small" @click="resetQuery">重置</el-button>
             <el-button
               style="margin-left:10px"
               type="warning"
               icon="el-icon-download"
               size="small"
               :loading="btnLoading"
               @click="handleExport"
             >导出</el-button>
           </el-form-item>
           <el-form-item style="margin-left: auto;">
              <MyTableColumnSet :tableColumn.sync="tableColumn" :hideTableColumn.sync="hideTableColumn" :tableColumnType.sync="tableColumnType"></MyTableColumnSet>
           </el-form-item>
         </el-form>
        </div>
        <div class="table orderTabel" ref="table">
          <el-table :data="dataList" style="width: 100%;" row-key="orderId" border :height="tableHeight" default-expand-all v-loading="loading">
            <el-table-column type="expand">
                <template slot-scope="scope">
                  <div class="item-box d-flex">
                    <div class="align-center  d-flex" style="width:550px" v-if="!hideTableColumn.includes('img')">
                      <div class="goodsBox">
                        <div class="img">
                          <el-image :src="scope.row.goodsDetail.goodsImage" fit="fill" v-image-preview="scope.row.goodsDetail.goodsImage"></el-image>
                        </div>
                        <div class="goodsRight">
                          <div class="goodsName color-444 ellipsis-item font-size-13">{{scope.row.goodsDetail.storeName}}</div>
                          <div class="goodsLabel d-flex">
                            <span style="font-size: 12px;color:#999">数量：{{scope.row.goodsNum}}</span>
                          <!-- <div class="color-999 d-flex margin-right-10 font-size-13">评分:<el-rate v-model="scope.row.newScore" :score-template="scope.row.score+''" allow-half disabled show-score text-color="#ff9900"></el-rate></div> -->
                          </div>
                        </div>
                      </div>
                    </div>

                    <div class="align-center justify-center d-flex" style="width:160px" v-if="!hideTableColumn.includes('allMoney')">
                        {{scope.row.actualPayPrice}}
                    </div>
                    <div class="align-center justify-center d-flex" style="width:160px" v-if="!hideTableColumn.includes('serviceCharge')">
                        {{scope.row.actualPayPrice}}
                    </div>
                    <div class="align-center justify-center d-flex" style="width:160px" v-if="!hideTableColumn.includes('phone')">
                        {{scope.row.telephone}}
                    </div>
                    <div class="align-center justify-center d-flex" style="width:160px" v-if="!hideTableColumn.includes('status')">
                        <el-tag :type="scope.row.listClass">{{scope.row.orderStatusName}}</el-tag>
                    </div>
                    <div class="align-center justify-center d-flex flex1"  v-if="!hideTableColumn.includes('applyRemark')">
                        <span class="ellipsis-item3">{{scope.row.remarks}}</span>
                    </div>
                  </div>
                </template>
              </el-table-column>
               <el-table-column prop="" label="门店信息" v-if="!hideTableColumn.includes('img')" width="550" >
                 <template #default="scope">
                  <div class="d-flex">
                    <span class="font-size-13 color-999 ">订单编号:{{ scope.row.orderCode }}</span>
                    <span class="font-size-13 color-999 margin-left-10">创建时间:{{ parseTime(scope.row.createTime) }}</span>
                  </div>
                 </template>
               </el-table-column>
              <el-table-column prop="" label="付款总金额(元) " v-if="!hideTableColumn.includes('allMoney')" align="center" width="160"></el-table-column>
              <el-table-column prop="" label="实收金额(元) " v-if="!hideTableColumn.includes('serviceCharge')" align="center" width="160"></el-table-column>
              <el-table-column prop="" label="用户手机号" v-if="!hideTableColumn.includes('phone')" align="center" width="160"></el-table-column>
              <el-table-column prop="" label="状态" v-if="!hideTableColumn.includes('status')" align="center"  width="160"> </el-table-column>
              <el-table-column prop="" label="支付备注" v-if="!hideTableColumn.includes('applyRemark')" align="center" > </el-table-column>
          </el-table>
        </div>
        <div class="page" ref="page">
          <MyPagination
             :total="total"
             :page.sync="searchForm.pageNum"
             :limit.sync="searchForm.pageSize"
             @pagination="dataInfo"
           />
        </div>
  </div>
</template>

<script>
  import common from '@/api/api';
  import {getOrderList,getOrderStatusCount,orderExport} from '@/api/getData'
  import option from '../../common/option.js';
  import Goods from '../order/components/goods'
  export default {
    components: {
      Goods
    },
    data() {
      let that = this;
      return {
        loading: false,
        userLoading: false,
        btnLoading:false,
        menuIndexStatus:'0',
        menuList:[
        ],
          orderTime:[],
        searchForm: {
          goodsName:"",
          goodsType:'',
          orderCode:'',
          orderStatus:'',
          telephone:'',

          pageNum: 1,
          pageSize: 20,
        },
        tableColumn:[{
            name:'门店',
            value:'img'
        },{
            name:'门店评分',
            value:'rate'
        },{
            name:'实际支付（元）',
            value:'allMoney'
        },{
            name:'用户状态',
            value:'userName'
        },{
            name:'服务费',
            value:'serviceCharge'
        },{
            name:'用户手机号',
            value:'phone'
        },{
            name:'状态',
            value:'status'
        },{
            name:'创建时间',
            value:'createTime'
        },{
            name:'支付备注',
            value:'applyRemark'
        }],
        hideTableColumn:[],/*自定义表格列需要隐藏的*/
        tableColumnType:'staffManagement',/*自定义表格列类型传参*/
        tableHeight:400,//table 高度
        dataList:[],
        total: 0,
        multipleSelection: '',
        dialogTitle: '',
        userFormVisible: false,
        afterInformationList:{},/*售后信息*/
        rules: { },
        areaProps: {
          lazy: true,
          checkStrictly: true,
          lazyLoad (node, resolve) {
            that.$axios({
              method: 'get',
              url: common.apihost+'/system/area/getList?pcode='+(node.value?node.value:'0'),
            }).then ((res) => {
              if (res.data.code == 200) {
                const nodes = res.data.data;
                nodes.forEach(item => {
                  item.value = item.code,
                  item.label = item.name,
                  item.leaf = item.level >= 5
                })
                resolve(nodes);
              } else {
                this.$message.error(res.msg)
              }
            })
          }
        },
      }
    },
    computed: {
      pickerOptions: () => {
        return option.pickerOptions;
      }
    },
    mounted() {
      this.getSelect();
      this.dataInfo();
      this.$nextTick(() => {
        console.log(this.$refs.menuList.offsetHeight)
          this.tableHeight = this.$refs.index.offsetHeight - this.$refs.menuList.offsetHeight  - this.$refs.search.offsetHeight - this.$refs.page.offsetHeight - 55;
      })
    },
    methods: {
      async dataInfo() {
        try {
          let data = this.addDateRange(this.searchForm, this.orderTime, 'startTime', 'endTime');
          this.loading = true;
          const result = await getOrderList(data);
          if (result.code == 200) {
            this.total = result.total;
            let list = result.rows;
            list.map(item=>{
              item.goodsDetail = JSON.parse(item.goodsInfo)
            })
            this.dataList = list;
          } else {
            this.$message.error(result.msg);
          }
          this.loading = false;
        } catch (err) {
          this.loading = false;
          console.log(err)
        }
      },
      /** 导出按钮操作 */
       handleExport() {
        let data = this.addDateRange(this.searchForm, this.orderTime, 'startTime', 'endTime');
         this.$modal.confirm('是否确认导出搜索数据项？').then(() => {
           this.btnLoading = true;
           return orderExport(data);
         }).then(response => {
           this.$download.name(response.msg);
           this.btnLoading = false;
         }).catch(() => {});
      },
      getSelect(){
        getOrderStatusCount().then((res) => {
          if (res.code == 200) {
            //this.menuList = res.data;
            let data = res.data;
            let topData = [{statusName:"全部订单",orderStatus:0,orderCount:0}];
            let total = 0;
            for(let i=0;i<data.length;i++){
              total += Number(data[i].orderCount)
            }
            console.log(total)
            topData[0].orderCount = total;
            this.menuList = topData.concat(res.data)
          }
        });
      },
      resetQuery() {
        this.orderTime = [];
        this.updateTime = [];
        this.resetForm("searchForm");
        this.dataInfo();
      },
      /** 头部数据点击 **/
      handleItem(id){
        this.searchForm.orderStatus = id;
        this.dataInfo();
      },
      handleSearch() {
        this.searchForm.pageNum= 1;
        this.dataInfo();
      },
    }
  }
</script>

<style scoped lang="scss">
    .searchAddress /deep/ .el-input{
      width:350px!important;
    }
    .orderTabel /deep/ .el-table__expand-icon{
      width:34px;
    }
    .activeCheckedBox{
      border-top: 1px solid #ddd;
      padding:10px;
      height:52px;
      .el-tag{
        margin-right:10px;
      }
    }
    .menuList{
      display: flex;
      margin-bottom: 15px;
      .menu-item{
        flex:1;
        padding:20px 20px 10px 20px;
        border:1px solid #DCDFE6;
        border-right: none;
        cursor: pointer;
        .numberBox{
          display:flex;
          justify-content:center;
        }
        .tipsNumber{
           font-size: 12px;
           height: 18px;
           line-height: 18px;
           padding: 0 6px;
           text-align: center;
           white-space: nowrap;
           position:absolute;
           background:#FF2F43;
           border-radius: 10px;
           right: -16px;
           top: -6px;
           color:#fff;
        }
        .number{
          font-size: 32px;
          position:relative;
        }
        .text{
          font-size: 16px;
          color:#333333;
          text-align: center;
        }
      }
    }
    .menuList .menu-item:last-child{
      border-right: 1px solid #DCDFE6;
    }
    .menuList .menu-item:hover{
      background-color:#D8E4DD;
    }
     .menuList .menu-item.active{
        background-color: #D8E4DD;
     }
     .formDialog /deep/ .el-form-item{
       margin-bottom: 5px;
     }

    .table /deep/ .el-table__expanded-cell{
     background: #FAFCFB;
      padding:0 50px;
    }
    .table /deep/ .el-table__expanded-cell:hover{
     background: #FAFCFB!important;
    }
    .table /deep/ .el-table__expanded-cell .el-form-item{
      margin-bottom: 0px;
      margin-right: 30px;
    }
    .table /deep/ .el-table__expanded-cell .el-form-item__label,.table /deep/ .el-table__expanded-cell .el-form-item__content{
       height: 54px;
       line-height: 54px;
    }
</style>
